<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <div>
            <input type="text" placeholder="请输入代办事项" v-model="text" @keydown.enter="add">
            <h1>正在进行中:</h1>
            <ul>
                <li v-for="(item,index) in todolist" :key="index">
                    <input type="checkbox" v-model="item.done" @click.prevent="todo(index)">
                    {{item.text}}
                </li>
            </ul>
            <h1>完成</h1>
            <ul>
                <li v-for="(item,index) in  donelist" :key="index">
                    <input type="checkbox" v-model="item.done" @click.prevent="done(index)">
                    {{item.text}}
                    <button @click="del(index)">删除</button>
                </li>
            </ul>
        </div>
    </div>
    <script src="./vue.js"></script>
    <script>
        /**
         * {
                text:'',
                done:false
            }
         * */ 
        let vm = new Vue({
            el:'#app',
            data:{
                todolist:[],
                donelist:[],
                text:'事项'
            },
            methods:{
                add(){
                    this.todolist.push({
                        text:this.text,
                        done:false
                    })
                    this.text = '';
                },
                todo(index){
                    let item = this.todolist[index];
                    item.done = true;
                    this.todolist.splice(index,1);
                    this.donelist.push(item);
                },
                done(index){
                    let item = this.donelist[index];
                    item.done = false;
                    this.donelist.splice(index,1);
                    this.todolist.push(item);
                },
                del(index){
                    this.donelist.splice(index,1);
                }
            }
        })
    </script>
</body>
</html>